using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCtl : MonoBehaviour
{
    private long lastInputTime;//上次输入时间
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        receiveInput();
    }

    //接收输入：键盘和轮盘，鼠标(鼠标的移动是直接替换当前的路点)
    private void receiveInput()
    {
        DateTime dateTime = DateTime.Now;
        int millisecond = dateTime.Millisecond;
        if (millisecond - lastInputTime >= 100)//接收输入
        {
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");
            if (h == 0 && v == 0)
            {
                return;
            }

            Vector2 direction = new Vector2(h, v);
            direction = direction.normalized;
            Vector2 move = direction * PlayerManager.getInstance().mainPlayer.speed * 0.1f;
            Vector3 targetPos = transform.position+new Vector3(move.x,move.y,0);
            PlayerManager.getInstance().mainPlayer.points.Add(targetPos);
            Req_Move reqMove = new Req_Move();
            reqMove.x = targetPos.x;
            reqMove.y = targetPos.y;
            NetWebSocket.SendMsg(reqMove);
        }
    }
}
